package dancrawler.client;

import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

/**
 *
 */
public class ImageLoader {
    private Map<String, Image> images;

    public ImageLoader()
    {
        images = new HashMap<>();
    }

    public Image load(String name)
    {
        if(images.containsKey(name))
        {
            return images.get(name);
        }
        else
        {
            try {
                URL url = Main.class.getResource("/res/img/" + name+".png");
                if(url == null)
                    return null;
                Image img = ImageIO.read(url);
                images.put(name, img);
                return img;
            } catch (IOException ex) {
                return null;
            }
        }
    }
}
